消消乐游戏def getSwappingCandy(board, firstXY, secondXY):
# 交换相邻糖果
firstCandy = {'imageNum': board[firstXY['x']][firstXY['y']],
'x': firstXY['x'],
'y': firstXY['y']}
secondCandy = {'imageNum': board[secondXY['x']][secondXY['y']],
'x': secondXY['x'],
'y': secondXY['y']}
highlightedCandy = None
# 左右相邻
if firstCandy['x'] == secondCandy['x'] 1 and firstCandy['y'] == secondCandy['y']:
firstCandy['direction'] = L
secondCandy['direction'] = R
elif firstCandy['x'] == secondCandy['x'] - 1 and firstCandy['y'] == secondCandy['y']:
firstCandy['direction'] = R
secondCandy['direction'] = L
# 上下相邻
elif firstCandy['y'] == secondCandy['y'] 1 and firstCandy['x'] == secondCandy['x']:
firstCandy['direction'] = U
secondCandy['direction'] = D
elif firstCandy['y'] == secondCandy['y'] - 1 and firstCandy['x'] == secondCandy['x']:
firstCandy['direction'] = D
secondCandy['direction'] = U
# 两个糖果不相邻就不能交换
else:
return None, None
return firstCandy, secondCandy # 此时两个糖果字典中的key值发生改变
评论